project(Cg)

set(Cg_INCLUDE_DIR "${Cg_SOURCE_DIR}/include" CACHE PATH "" FORCE)

if (WIN32)
  # manually copy to build and install the correct DLL
  if (OGREDEPS_PLATFORM_X64)
    set(CG_DLL bin64/cg.dll)
    set(Cg_LIBRARY_REL "${Cg_SOURCE_DIR}/lib64/cg.lib" CACHE PATH "" FORCE)
    set(Cg_LIBRARY_DBG "${Cg_SOURCE_DIR}/lib64/cg.lib" CACHE PATH "" FORCE)
  else ()
    set(CG_DLL bin/cg.dll)
    set(Cg_LIBRARY_REL "${Cg_SOURCE_DIR}/lib/cg.lib" CACHE PATH "" FORCE)
    set(Cg_LIBRARY_DBG "${Cg_SOURCE_DIR}/lib/cg.lib" CACHE PATH "" FORCE)
  endif ()
  install(FILES ${CG_DLL} DESTINATION bin/Release)
  install(FILES ${CG_DLL} DESTINATION bin/Debug)
  if (MINGW)
    file(COPY ${CG_DLL} DESTINATION ${OGREDEPS_RUNTIME_OUTPUT})
  else ()
    file(COPY ${CG_DLL} DESTINATION ${OGREDEPS_RUNTIME_OUTPUT}/Debug)
    file(COPY ${CG_DLL} DESTINATION ${OGREDEPS_RUNTIME_OUTPUT}/Release)
  endif ()
elseif (APPLE AND NOT OGRE_BUILD_PLATFORM_APPLE_IOS)
  add_custom_target(Cg COMMAND 
    unzip lib/Cg.framework.zip -d ${OGREDEPS_BINARY_DIR}/../${OGREDEPS_LIB_DIRECTORY}
    WORKING_DIRECTORY ${Cg_SOURCE_DIR}
    COMMENT "Unzipping Cg framework" VERBATIM
  )
elseif (UNIX)
  # manually install the correct .so
  if (OGREDEPS_PLATFORM_X64)
    install(FILES lib64/libCg.so DESTINATION ${OGREDEPS_LIB_DIRECTORY})
    set(Cg_LIBRARY_REL "${Cg_SOURCE_DIR}/lib64/libCg.so" CACHE PATH "" FORCE)
    set(Cg_LIBRARY_DBG "${Cg_SOURCE_DIR}/lib64/libCg.so" CACHE PATH "" FORCE)
  else ()
    install(FILES lib/libCg.so DESTINATION ${OGREDEPS_LIB_DIRECTORY})
    set(Cg_LIBRARY_REL "${Cg_SOURCE_DIR}/lib/libCg.so" CACHE PATH "" FORCE)
    set(Cg_LIBRARY_DBG "${Cg_SOURCE_DIR}/lib/libCg.so" CACHE PATH "" FORCE)
  endif ()
endif ()

if (OGREDEPS_INSTALL_DEV)
  install(DIRECTORY include/ DESTINATION include)
  if (WIN32)
    # install the correct lib
    if (OGREDEPS_PLATFORM_X64)
      install(FILES lib64/cg.lib DESTINATION ${OGREDEPS_LIB_DIRECTORY}/Debug)
      install(FILES lib64/cg.lib DESTINATION ${OGREDEPS_LIB_DIRECTORY}/Release)
    else ()
      install(FILES lib/cg.lib DESTINATION ${OGREDEPS_LIB_DIRECTORY}/Debug)
      install(FILES lib/cg.lib DESTINATION ${OGREDEPS_LIB_DIRECTORY}/Release)
    endif ()
  endif ()
endif ()
